/**
 * @copyright 2017 sinping.com 北京芯平科技股份有限公司. All rights reserved.
 * 本内容仅限于北京芯平科技股份有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */

package com.sinping.qh.dto.auth;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Converter;
import com.sinping.qh.domain.auth.Role;
import com.sinping.qh.utils.mapper.BeanMapper;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 角色传输对象
 *
 * @author 刘庆沛
 * @create 2017/12/25
 */
public class RoleDTO  implements Serializable {

    private static final long serialVersionUID = 1L;

    private String id;

    /**
     * 角色名
     */
    private String role;
    /**
     * 0：正常1：异常
     */
    private Integer status;

    /**
     * 角色描述
     */
    private String desc;

    /**
     * 是否安全员
     */
    private String security;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    @JsonProperty(value = "create_time")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    @JsonProperty(value = "update_time")
    private Date updateTime;

    @JsonProperty(value = "permission")
    private String permission;


    /**
     * 角色拥有的资源id列表
     */
    private List<String> resources;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public List<String> getResources() {
        return resources;
    }

    public void setResources(List<String> resources) {
        this.resources = resources;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getSecurity() {
        return security;
    }

    public void setSecurity(String security) {
        this.security = security;
    }



    public Role convertToRole(){
        RoleDTOConvert roleDTOConvert=new RoleDTOConvert();
        return roleDTOConvert.convert(this);
    }

    public RoleDTO convertFor(Role role){
        RoleDTOConvert roleDTOConvert=new RoleDTOConvert();
        return roleDTOConvert.reverse().convert(role);
    }

    private static class RoleDTOConvert extends Converter<RoleDTO,Role> {

        @Override
        protected Role doForward(RoleDTO roleDTO) {
            return BeanMapper.map(roleDTO, Role.class);
        }

        @Override
        protected RoleDTO doBackward(Role role) {
            return BeanMapper.map(role, RoleDTO.class);
        }
    }

}
